package websocket.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import websocket.socket_.WebSocketServer;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class ConfigProperties {


    private static final Logger logger = LoggerFactory.getLogger(Object.class.getName());

    public Map<String, String> getPropertiesMap(String fileName) {
        Map<String, String> map = new HashMap<String, String>();
        Properties prop = new Properties();
        InputStream in = null;
        try {
            in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
//            in = Object.class.getResourceAsStream(fileName);
            prop.load(in);

            Set<String> set = prop.stringPropertyNames();
            for (String s : set) {
                String value = prop.getProperty(s);
                if (value != null) {
                    map.put(s, value);
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    logger.error(e.getMessage());
                }
            }
        }

        return map;
    }
}
